package controllers.manage.product;

import controllers.BaseController;
import controllers.auth.Secure;
import helper.GlobalConfig;
import models.merchant.Merchant;
import org.apache.commons.lang.StringUtils;
import play.modules.paginate.JPAExtPaginator;
import play.mvc.Controller;
import play.mvc.With;
import product.Product;
import product.ProductNeed;
import product.type.ProductType;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/20.
 */
@With(BaseController.class)
public class ProductNeedCtrl extends Controller {

    public static void index(Integer pageNumber, String name,String content){
//        Merchant merchant = Secure.getLoginUser().merchant;
        pageNumber = pageNumber == null ? 1 : pageNumber;
        Map<String , Object> searchMap = new HashMap<>();
        if(StringUtils.isNotBlank(name)){
            searchMap.put("name", "%"+name+"%");
        }
        if(StringUtils.isNotBlank(content)){
            searchMap.put("content", "%"+content+"%");
        }
        JPAExtPaginator<Product> resultPage = ProductNeed.findByCondition(searchMap, "createAt desc", pageNumber, GlobalConfig.PAGE_SIZE);
        render(resultPage, pageNumber,name,content);
    }
}
